package eyal.com;

import android.graphics.Color;
import android.media.MediaPlayer;
import android.widget.LinearLayout;

public class RefreshStateMachine {
	
	private RefreshState mState;
	private LinearLayout mLayout;
	private MediaPlayer mediaPlayer;
	
	public RefreshStateMachine(LinearLayout l, MediaPlayer player) {
		this.mState = RefreshState.NONE;
		this.mLayout = l;
		this.mediaPlayer = player;
		mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
			@Override
			public void onCompletion(MediaPlayer mp) {
				mp.reset();
				mp.start();
			}
		});
	}
	
	public RefreshState getmState() {
		return mState;
	}
	
	public LinearLayout getLayout(){
		return mLayout;
	}

	public void setState(RefreshState state) {
		this.mState = state;
		switch (mState) {
			case NONE: 
				mLayout.setBackgroundColor(Color.BLACK);
				mediaPlayer.pause();
				break;
				
			case MUSIC:
				mLayout.setBackgroundColor(Color.BLACK);
				mediaPlayer.start();
				break;
				
			case BACKGROUND:
				mLayout.setBackgroundColor(Color.RED);
				mediaPlayer.pause();
				break;
				
			case MUSIC_AND_BACKGROUND:
				mLayout.setBackgroundColor(Color.RED);
				mediaPlayer.start();
				break;
				
		}
	}
	
	
}
